<template>
	<view class="container">
		<u-toast ref="uToast"></u-toast>
		<view class="box">
			<!-- 注意，如果需要兼容微信小程序，最好通过setRules方法设置rules规则 -->
			<u--form labelPosition="left" :model="option" labelWidth='100px' :labelStyle='labelStyle' border>
				<u-form-item label="管控措施名称" borderBottom>
					<u--input v-model="option.mc" border="none" placeholder="请输入巡检人" disabled disabledColor='#fff'>
					</u--input>
				</u-form-item>
				<u-form-item label="巡检人" borderBottom>
					<u--input v-model="option.name" border="none" placeholder="请输入巡检人" disabled disabledColor='#fff'>
					</u--input>
				</u-form-item>
				<u-form-item label="巡检单位" borderBottom>
					<u--input v-model="option.checkCycleUnit" disabled disabledColor='#fff' border="none"
						placeholder="请选择巡检单位"></u--input>
				</u-form-item>
				<u-form-item label="巡检周期" borderBottom @click="show = true,pickerShowType=3">
					<u--input v-model="option.checkCycle" disabled disabledColor='#fff' border="none"
						placeholder="请选择巡检周期"></u--input>
				</u-form-item>
				<u-form-item label="隐患排查类型" borderBottom>
					<u--input v-model="option.troubleshootContents" disabled disabledColor='#fff' border="none">
					</u--input>
				</u-form-item>
				<view style="color: #838383;padding: 10px 0">隐患排查内容</view>
				<!--				<u-form-item label="隐患排查内容">-->
				<textarea v-model="option.content" height="120" disabled disabledColor='#fff'
					style="background:#f6f6f6;margin-bottom: 30px;width: 100%!important;"></textarea>
				<!--				</u-form-item>-->
			</u--form>
		</view>
		<view class="butt">
			<u-button type="primary" text="开始巡检" @click="submit" class='but'></u-button>
		</view>
		<!--    <u-picker :show="show" :columns="columns" @cancel="show = false" @confirm="confirm"></u-picker>-->
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		intelligentDetailAPI,
		startInspectionAPI
	} from "../../../api/api";
	import {
		URL
	} from '@/api/request.js'
	export default {
		data() {
			return {
				type:null,
				option: {
					checkTypes: '',
					troubleshootContents: '',
				},
				pickerShowType: 0,
				show: false,
				columns: [],
				labelStyle: {
					color: '#666'
				},
			}
		},
		onLoad(option) {
			this.id = option.id
			this.type = option.type

		},
		mounted() {
			intelligentDetailAPI({
				id: this.id
			}).then((r) => {
				this.option = r.data
				switch (this.option.checkType) {
					case 1:
						this.option.troubleshootContents = '综合性检查'
						break;
					case 2:
						this.option.troubleshootContents = '专业性检查'
						break;
					case 3:
						this.option.troubleshootContents = '季节性检查'
						break;
					case 4:
						this.option.troubleshootContents = '日常性检查'
						break;
					case 5:
						this.option.troubleshootContents = '节假日检查'
						break;
					case 6:
						this.option.troubleshootContents = '外部检查等'
						break;
					default:
						this.option.troubleshootContents = '错误'
				}
				this.option.mc = r.data.gkcs.split('|')[0]
				this.option.content = r.data.gkcs.split('|')[1]
			})
		},
		methods: {
			upImg(path) {
				uni.uploadFile({
					url: URL + `/common/upload`,
					filePath: path,
					header: {
						'Authorization': `Bearer ${uni.getStorageSync('token')}`
					},
					name: 'file',
					success: (res) => {
						this.option.xgfj = JSON.parse(res.data).url
						this.list.push(res.url)
						this.option.pz = JSON.parse(res.data).url
					}
				});
			},
			submit() {
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['camera'], //从相册选择、摄像头
					success: (res) => {
						let that = this
						if (res.errMsg == 'chooseImage:ok') {
							this.list = []
							this.imageList = []
							res.tempFilePaths.forEach(item => {
								that.imageList.push(item)
							})
							that.imageList.forEach(item => {
								this.upImg(item)
							})
							//   startInspectionAPI({...this.option}).then((r)=>{
							//     if (r.code === 200){
							//       this.$refs.uToast.show({
							//         type: 'success',
							//         title: '新增成功',
							//         message: "新增成功",
							//         iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							//       })
							//       setTimeout((e)=>{
							// uni.navigateBack({
							// 	delta: 1
							// })
							//       },2000)
							//     }
							//   })
							uni.navigateTo({
								url: `../hiddenDanger/hiddenDanger?details=${JSON.stringify(this.option)}&type=${this.type}`
							})
						}
					}

				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		height: calc(100vh - 40px);
		padding: 40rpx 24rpx 0 24rpx;
		background-color: #f6f6f6;

		.box {

			background-color: #fff;
			padding: 10rpx 30rpx;
			border-radius: 20rpx;

			.butt {
				margin-top: 30rpx;
			}
		}
	}
</style>
